package td.server.pt;

import java.util.Date;

import td.domain.Survey;
import td.server.dao.SurveyDao;
import td.shared.action.SurveyAction;
import td.shared.action.SurveyActionResult;

import com.google.inject.Inject;
import com.gwtplatform.dispatch.server.ExecutionContext;
import com.gwtplatform.dispatch.server.actionhandler.ActionHandler;
import com.gwtplatform.dispatch.shared.ActionException;

public class SurveyActionActionHandler implements
		ActionHandler<SurveyAction, SurveyActionResult> {

	@Inject
	SurveyDao surveyDao;

	@Inject
	public SurveyActionActionHandler() {
	}

	@Override
	public SurveyActionResult execute(SurveyAction action,
			ExecutionContext context) throws ActionException {
		Survey survey = action.getSurveyEntry();
		survey.setDate(new Date());
		surveyDao.putNow(survey);
		return new SurveyActionResult(true);
	}

	@Override
	public void undo(SurveyAction action, SurveyActionResult result,
			ExecutionContext context) throws ActionException {
	}

	@Override
	public Class<SurveyAction> getActionType() {
		return SurveyAction.class;
	}
}
